/*
 * @Author: mikey.zhaopeng
 * @Date:   2016-02-02 15:17:35
 * @Last Modified by:   mikey.zhaopeng
 * @Last Modified time: 2016-07-13 16:00:48
 * @首页
 */
'use strict';
require(['./config'], function() {
    // 全局加入replaceAll
    String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
        if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
            return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
        } else {
            return this.replace(reallyDo, replaceWith);
        }
    }


    require(['jquery'], function($) {
        window.j$ = $;
        require(['moment', 'underscore'], function(moment, _) {
            window.moment = moment;
            window._ = _;
            require(['language'], function(I18N) {
                window.I18N = I18N;
                require(['./modules/common/kit'], function(kit) {
                    window.kit = kit;
                    window.Kit = kit;
                    require(['./app/framework/bean/version'], function(versionModel) {
                        versionModel.queryVersion(function(version) {
                            window.fmpversion = version.version;
                            require(['./modules/common/checkuser'], function(checkuser) {
                                checkuser.valicateIsLogin(function() {
                                    require(['./app/framework/kernel/core'], function(core) {
                                        require(['bootstrap'], function() {
                                            window.checkuser = checkuser;
                                            require([
                                                'com/ndpmedia/vis/ChartWidget',
                                                'com/ndpmedia/vis/ChartEventListener',
                                                'oneYAxis',
                                                'twoYAxis',
                                                'listManagerConfig',
                                                'bootstrap',
                                                'select2',
                                                'daterange',
                                                'ztree',
                                                'jquery-nicescroll',
                                                'fileUploader',
                                                'listManager',
                                                'jquery-html5Validate',
                                                './modules/plugins/dialog',
                                                'fileinput',
                                                'lazyload',
                                                'di',
                                                'pagination',
                                                'sinput',
                                                'tabs',
                                                'vList2',
                                                'alert',
                                                'confirm',
                                                'treable',
                                                'drop',
                                                'drop2',
                                                'drop3',
                                                'table',
                                                'page',
                                                'sidepanel',
                                                'sinput',
                                                'blend',
                                                'progressbar',
                                                'tip',
                                                'dropsort',
                                                'field',
                                                'plgDrop',
                                                'bubble',
                                                'prompt',
                                                'jstep'
                                            ], function(
                                                ChartWidget,
                                                ChartEventListener,
                                                oneYAxis,
                                                twoYAxis
                                            ) {
                                                //配置列表全局常量 i18n使用语言
                                                listManagerConfig['i18n'] = I18N.language || 'zh-cn'
                                                window.ChartWidget = ChartWidget;
                                                window.ChartEventListener = ChartEventListener;
                                                window.oneYAxis = oneYAxis;
                                                window.twoYAxis = twoYAxis;
                                                //处理 drop无法下拉的问题

                                                $.fn.select2.amd.require(['select2/selection/search'], function(Search) {
                                                    var oldRemoveChoice = Search.prototype.searchRemoveChoice;
                                                    Search.prototype.searchRemoveChoice = function() {
                                                        oldRemoveChoice.apply(this, arguments);
                                                        this.$search.val('');
                                                    };
                                                    require(['./app/framework/layout2'], function(layout2) {
                                                        layout2.startup();
                                                    });
                                                });

                                                requirejs(['require', 'jquery', 'masonry'],
                                                    function(require, $, Masonry) {
                                                        require(['jqueryBridget'],
                                                            function(jQueryBridget) {}
                                                        );
                                                    });
                                            });
                                        });
                                    });
                                })
                            });
                        });
                    });
                })

            })
        })

    })

});
